<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>李宁体育</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="<%=path%>/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="<%=path%>/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="<%=path%>/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="<%=path%>/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="<%=path%>/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="<%=path%>/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css"
          rel="stylesheet">
    <link href="<%=path%>/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="<%=path%>/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    <style type="text/css">
    	.te {
    		margin:0;
    		overflow:hidden;
    	}
    	.edui-modal {
    		position: absolute;
    		top: -270px;
    	}
    	.edui-tab-nav .edui-tab-item:last-child {
    		display:none;
    	}
    </style>
</head>
<body class="gray-bg"  onload="selectionGenre();">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>修改商品</h5>                
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" action="productInfoFormMall.do" method="post" id="productInfoMallUpdate" enctype="multipart/form-data">
                                    <input type="hidden" name="id" id="id" value="${productInfo.id}"/>
                                    <input type="hidden" name="editSpecShoes" id="editSpecShoes" value="${productInfo.specShoes}"/>
                                    <input type="hidden" name="editClothesSize" id="editClothesSize" value="${productInfo.clothesSize}"/>
                                    <input type="hidden" name="prodT" id="prodT" value="${productInfo.prodType}"/>
                                    
                                    <div class="form-group">
									   <label class="col-sm-2 control-label">商品名称</label><font id="errName" color="red">*</font>
									   <div class="col-sm-3">
											<input type="text" class="form-control" name="name" id="name" value="${productInfo.name}" placeholder="商品名称"></input>
									   </div>
                                    </div> 
                                   <div class="form-group">
										<label class="col-sm-2 control-label">产品类型</label>
										<div class="col-sm-3">
										  <select class="form-control m-b" name="prodType" id="prodType" disabled="disabled">											
                                               <option value="1" <c:if test="${productInfo.prodType eq '1'}">selected="selected"</c:if>>券</option>
                                               <option value="2" <c:if test="${productInfo.prodType eq '2'}">selected="selected"</c:if>>实物</option>
                                          </select>
										</div>
									</div>
                                    <div id="colourDiv">
                                    <div class="form-group">
									   <label class="col-sm-2 control-label">商品颜色</label><font color="red">*</font>
									   <div class="col-sm-3">
											<input type="text" class="form-control" name="colour" id="colour" value="${productInfo.colour}" placeholder="商品颜色 "></input>
									   </div>
                                    </div>                             
									<div class="form-group">
										<label class="col-sm-2 control-label">鞋子规格</label>
										<div class="col-sm-8">
											<input type="checkbox"  name="specShoes" id="specShoes" value="29"/>&nbsp;29&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="30"/>&nbsp;30&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="31.5"/>&nbsp;31.5&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="33"/>&nbsp;33&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="34"/>&nbsp;34&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="35"/>&nbsp;35&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="35.5"/>&nbsp;35.5&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="36"/>&nbsp;36&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="37"/>&nbsp;37&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="37.5"/>&nbsp;37.5&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="38"/>&nbsp;38&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="39"/>&nbsp;39&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="39.5"/>&nbsp;39.5&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="40"/>&nbsp;40&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="41"/>&nbsp;41&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="41.5"/>&nbsp;41.5&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="42"/>&nbsp;42&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="43"/>&nbsp;43&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="43.5"/>&nbsp;43.5&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="44"/>&nbsp;44&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="45"/>&nbsp;45&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="45.5"/>&nbsp;45.5&nbsp;&nbsp;
											<input type="checkbox"  name="specShoes" id="specShoes" value="46"/>&nbsp;46
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">衣服尺码</label>
										<div class="col-sm-8">
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="110"  onchange="isChecked();"/>&nbsp;110&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="120"  onchange="isChecked();"/>&nbsp;120&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="130"  onchange="isChecked();"/>&nbsp;130&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="140"  onchange="isChecked();"/>&nbsp;140&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="150"  onchange="isChecked();"/>&nbsp;150&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="160"  onchange="isChecked();"/>&nbsp;160&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="165"  onchange="isChecked();"/>&nbsp;165&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="170"  onchange="isChecked();"/>&nbsp;170&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="SX"  onchange="isChecked();"/>&nbsp;SX&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="S"  onchange="isChecked();"/>&nbsp;S&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="M"  onchange="isChecked();"/>&nbsp;M&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="L"  onchange="isChecked();"/>&nbsp;L&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="XL"  onchange="isChecked();"/>&nbsp;XL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="XXL"  onchange="isChecked();"/>&nbsp;XXL&nbsp;&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="3XL"  onchange="isChecked();"/>&nbsp;3XL&nbsp;&nbsp;
											<input type="checkbox"  name="clothesSize" id="clothesSize" value="4XL"  onchange="isChecked();"/>&nbsp;4XL										
										</div>
									</div>
									</div>	
									<div id="skuDiv"> 								
									<div class="form-group">
										<label class="col-sm-2 control-label">SKU编码</label><font id="errSku" color="red"></font>
										<div class="col-sm-3">
											<input type="text" class="form-control" name="sku" id="sku" value="${productInfo.sku}" readonly="readonly"  style="border-left:0px;border-top:0px;border-right:0px;border-bottom:1px"/>
										</div>
									</div>
									</div>																		
									<div class="form-group">
										<label class="col-sm-2 control-label">销售积分</label><font id="errSalePoints" color="red">*</font>
										<div class="col-sm-3">
											<input type="text" class="form-control" name="salePoints" id="salePoints" value="${productInfo.salePoints}" placeholder="销售积分"></input>
										</div>
									</div>								
									<div class="form-group">
										<label class="col-sm-2 control-label">库存</label><font id="errStockQty" color="red">*</font>
										<div class="col-sm-3">
											<input type="text" class="form-control" name="stockQty" id="stockQty"  value="${productInfo.stockQty}" placeholder="库存"></input>
										</div>
									</div>									
									
									<div id="couponTemplateIdDiv" class="form-group">
									<label class="col-sm-2 control-label">优惠券模板ID</label><font color="red">*</font>
									<div class="col-sm-3">
										<select class="chosen-select form-control" name="couponTemplateId" id="couponTemplateId">
											<!-- <option value=""></option>  -->
											<c:forEach items="${wxCardConfigList}" var="wxCardConfig">
												<option value="${wxCardConfig.templateId}" <c:if test="${wxCardConfig.templateId == productInfo.couponTemplateId}">selected</c:if>>${wxCardConfig.name}</option>
											</c:forEach>
										</select>
									</div>
								    </div>
									<div class="form-group">
										<label class="col-sm-2 control-label">商品图</label><font id="errPicture" color="red"></font>
										<div class="col-sm-3">
											<input id="picture" name="picture" type="file"  maxlength="64" title="图片" placeholder="图片" onchange="validateImg();"/> 
										    <span id="imgHint" style="color:red">图片比例1:1,建议尺寸750x750px,大小不能超过1M</span>
										    <!-- </br>
										    <span id="imgsize" style="color:red"></span> -->
										</div>
									</div>	
									<div class="form-group">
										<label class="col-sm-2 control-label">是否上架</label>
										<div class="col-sm-3">
										   <select class="form-control m-b" name="shelves" id="shelves">
												<option value="1" <c:if test="${productInfo.shelves eq '1'}">selected="selected"</c:if>>上架</option>
												<option value="0" <c:if test="${productInfo.shelves eq '0'}">selected="selected"</c:if>>下架</option>
											</select>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">是否热门兑换</label>
										<div class="col-sm-3">
										   <select class="form-control m-b" name="isHot" id="isHot">
												<option value="0" <c:if test="${productInfo.isHot eq '0'}">selected="selected"</c:if>>是</option>
												<option value="1" <c:if test="${productInfo.isHot eq '1'}">selected="selected"</c:if>>否</option>
											</select>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">排序</label><font id="errSort" color="red"></font>
										<div class="col-sm-3">
											<input type="text" class="form-control" id="sort" name="sort" value="${productInfo.sort}" ></input>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">商品详情</label>
										<div class="col-sm-8">
										    <script type="text/plain" id="details" name="details" style="width:100%; height:150px">${productInfo.details}</script>
											<!-- <textarea id="details" style="width:240px; height:150px" name="details"></textarea> -->											
										</div>
									</div>																										
									<div class="form-group">
                                         <div class="col-sm-4 col-sm-offset-3">
                                          <button class="btn btn-primary" type="button" onclick="submitForm();">保 存</button>
                                          &nbsp;<button class="btn btn-info" type="button" onclick="goBackProduct()">返  回</button>
                                         </div>
                                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="<%=path%>/js/jquery.min.js?v=2.1.4"></script>
<script src="<%=path%>/js/bootstrapValidator.min.js"></script>
<!--下拉框-->
<script src="<%=path%>/js/plugins/chosen/chosen.jquery.js"></script>

<script src="<%=path%>/umeditor/third-party/template.min.js"></script>
<script src="<%=path%>/umeditor/umeditor.config.js"></script>
<script src="<%=path%>/umeditor/umeditor.min.js" type="text/javascript" charset="utf-8"></script>
<script src="<%=path%>/umeditor/lang/zh-cn/zh-cn.js"></script>
<script>
var um = UM.getEditor('details', {
	fullscreen : false,
	toolbar:[
        'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
        'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize' ,
        '| justifyleft justifycenter justifyright justifyjustify |',
        'link unlink | emotion image video  | map',
        '| horizontal print preview'
    ]
});
//um.setDisabled();
function submitForm() {
	var name = $("#name").val();
	var sku = $("#sku").val();
	var salePoints = $("#salePoints").val();
	var stockQty = $("#stockQty").val();
	var sort = $("#sort").val();
	var prodType = $("#prodType").val();
	if(name==''){
		$("#errName").html('名称不能为空');
		return false;
	}
	if(prodType==2){
		 if(sku==''){
    	    $("#errSku").html('sku编码不能为空');
    	    return false;
	     } 
	}
    if(salePoints==''){
    	$("#errSalePoints").html('销售积分不能为空');
    	return false;
    }
    if(stockQty==''){
    	$("#errStockQty").html('库存不能为空');
    	return false;
	}
    if(sort==''){
    	$("#errSort").html('排序不能为空');
    	return false;
    }
    document.getElementById("productInfoMallUpdate").submit();
}
function validateImg(){
	   var maxsize = 1*1024*1024;  //1M  
	   var img = $("#picture").val().toLowerCase().split('.');
	   var obj_file = document.getElementById("picture"); 
	   if(img == ''){   
	   }else{
		   if (img[img.length - 1] == 'gif' || img[img.length - 1] == 'jpg'|| img[img.length - 1] == 'jpeg'|| img[img.length - 1] == 'png') {
			   var filesize = 0;  
               filesize = obj_file.files[0].size
               if(filesize>maxsize){
            	   /* errMsg = "上传的图片文件不能超过1M！";
            	   $("#imgsize").html(errMsg) */
            	   $("#picture").val("");
                   return false;
               }
		   }else{
			   $("#picture").val("");
			   return false;
		   }  
	   }	  
 }
   $("#prodType").change(function(){
	  if(this.value == "2") {
		 $("#couponTemplateIdDiv").hide();
		 $("#colourDiv").show();
	  }else if(this.value == "1"){
		 $("#couponTemplateIdDiv").show();
		 $("#colourDiv").hide();
	  }	  
   });
   function selectionGenre(){
	   if($("#prodType").val() == "2"){
		   $("#colourDiv").show();
		   $("#skuDiv").show();
	   }else{
		   $("#colourDiv").hide();
		   $("#skuDiv").hide();
	   }
   }
   $(document).ready(function(){
       var prodType = $("#prodType").val();
       if(prodType=='2'){
    	   $("#couponTemplateIdDiv").hide(); 
       }
       var shoes = $("#editSpecShoes").val();
       var size = $("#editClothesSize").val();
       if(shoes!=''){
    	   $(shoes.split(",")).each(function (i,dom){
    	          $(":checkbox[value='"+dom+"']").prop("checked",true);
    	          $(":checkbox[id='"+dom+"']").prop("checked",true);
    	   });
       }
       if(size!=''){
    	   $(size.split(",")).each(function (i,dom){
    	          $(":checkbox[value='"+dom+"']").prop("checked",true);
    	          $(":checkbox[id='"+dom+"']").prop("checked",true);
    	   });
       }
    });
    //判断是否选中
    function isChecked(){
    	var obj=document.getElementsByName('specShoes'); 
    	var objSize=document.getElementsByName('clothesSize'); 
    	var val='';
    	var valSiz='';
    	for(var i=0; i<obj.length; i++){
    	    if(obj[i].checked) val+=obj[i].value+',';
    	} 
    	for(var j=0; j<objSize.length; j++){
    	    if(objSize[j].checked) valSiz+=objSize[j].value+',';
    	}    	
    	if(val==''||val==null){
    		
    	}else{
    		$(valSiz.split(",")).each(function (i,dom){
    		      $(":checkbox[value='"+dom+"']").prop("checked",false);
    		      $(":checkbox[id='"+dom+"']").prop("checked",false);
    		});
    		alert("不好意思(规格和尺码只能二选一)");
    	}
    	$("#specShoesVal").val(val);
    	$("#clothesSizeVal").val(valSiz);
    }
    function goBackProduct() {
        window.location.href="<%=path%>/productInfo/queryProductInfoMallList";
	}
    
    //表单验证
    var config = {
            ".chosen-select": {},
            ".chosen-select-deselect": {allow_single_deselect: !0},
            ".chosen-select-no-single": {disable_search_threshold: 10},
            ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
            ".chosen-select-width": {width: "95%"}
    };
    
    for (var selector in config)$(selector).chosen(config[selector]);
    $(document).ready(function () {
        $('#productInfoMall').bootstrapValidator({
            message: 'This value is not valid',
            fields: {
                name: {
                    message: '商品名称不能为空！',
                    validators: {
                        notEmpty: {
                            message: '商品名称不能为空！'
                        }
                    }
                },
                colour: {
                    message: '商品颜色不能为空！',
                    validators: {
                        notEmpty: {
                            message: '商品颜色不能为空！'
                        }
                    }
                },                           
                salePoints: {
                    message: '销售积分不能为空！',
                    validators: {
                        notEmpty: {
                            message: '销售积分不能为空！'
                        }
                    }
                },
                stockQty: {
                    message: '库存不能为空！',
                    validators: {
                        notEmpty: {
                            message: '库存不能为空！'
                        }
                    }
                },
                genre: {
                    message: '分类不能为空！',
                    validators: {
                        notEmpty: {
                            message: '分类不能为空！'
                        }
                    }
                },
            },
            submitHandler: function(validator, form, submitButton) {
            }
        });
    });
    <%-- function checkSort(){
      	 var sort = $("#sort").val();
      	 if(sort==null || sort==''){     		
      	 }else{
      		$.ajax({
      	        url: "<%=path%>/productInfo/toCheckSort",
      	        type: "post",
      	        data: {"sort": sort},
      	        dataType: "json",
      	        success: function (data) {   	              
      	              if(data.status=='400'){ 
      	            	 $("#errSort").html(data.msg); 
      	            	 $("#sort").val("");
      	            	 return false;  
      	              }  	              
      	        },
      	        error: function () {
      	            alert("异常，请稍后重试");
      	        }
      	  });
      	 }        
      } --%>
</script>
</body>
</html>
